'use strict';

const db = uniCloud.database()
const postsCollection = db.collection('posts')

exports.main = async (event, context) => {
	try {
		const { postId } = event
		
		if (!postId) {
			return {
				code: -1,
				msg: '帖子ID不能为空',
				data: null
			}
		}
		
		// 获取帖子详情
		const post = await postsCollection.doc(postId).get()
		
		if (!post.data || post.data.length === 0) {
			return {
				code: -1,
				msg: '帖子不存在',
				data: null
			}
		}
		
		return {
			code: 0,
			msg: '获取成功',
			data: post.data[0]
		}
	} catch (error) {
		console.error('获取帖子详情失败', error)
		return {
			code: -1,
			msg: '获取失败',
			data: null
		}
	}
} 